package com.zhentao.filter;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.CrossOrigin;

@Configuration
@CrossOrigin(origins = "*")
public class GatewayRoutes {

    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("finance_route", r -> r.path("/finance/**")
                        .filters(f -> f.rewritePath("/finance/(?<segment>.*)", "/api/finance/${segment}"))
                        .uri("http://localhost:8093"))
                .route("system_route", r -> r.path("/system/**")
                        .uri("http://localhost:8000"))
                .build();
    }
}
